#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include <algorithm>
#include<vector>
using namespace std;

void vector_test01()
{
	vector<int> v1();
	vector<int> v2(5,20);
	vector<int> v3(v2);
	vector<int> v4(v2.begin()+1,v2.end());

	for (auto e : v2)
	{
		cout << e << " ";
	}
	cout << endl;

	for (auto e : v3)
	{
		cout << e << " ";
	}
	cout << endl;

	for (auto e : v4)
	{
		cout << e << " ";
	}
	cout << endl;
}

void vector_test02()
{
	vector<int> v1({1,2,3,4,5,6});
	vector<int>::iterator it1 = v1.begin();
	while (it1 != v1.end())
	{
		cout << *it1 << " ";
		it1++;
	}
	cout << endl;
}

void vector_test03()
{
	vector<int> v1({10,20,30,40,50,60});
	cout << v1.size() << endl;//6

	v1.resize(5);
	for (auto e : v1)
	{
		cout << e << " ";
	}//10 20 30 40 50
	cout << endl;

	v1.resize(8, 100);
	for (auto e : v1)
	{
		cout << e << " ";
	}//10 20 30 40 50 100 100 100
	cout << endl;

	v1.resize(12);
	for (auto e : v1)
	{
		cout << e << " ";
	}//10 20 30 40 50 100 100 100 0 0 0 0
	cout << endl;

	cout << v1.capacity() << endl;//13
	v1.reserve(50);
	cout << v1.capacity() << endl;//50

	v1.shrink_to_fit();
	cout << v1.size() << endl;//12
	cout << v1.capacity() << endl;//12

	cout << v1.empty() << endl;//0

}

void vector_test04()
{
	vector<int> v1;
	v1.push_back(1);
	v1.push_back(2);
	v1.push_back(3);
	v1.push_back(4);
	v1.push_back(5);
	for (const auto& e : v1)
	{
		cout << e << " ";
	}//1 2 3 4 5
	cout << endl;

	v1.pop_back();
	v1.pop_back();
	auto it1 = v1.begin();
	while (it1 != v1.end())
	{
		cout << *it1++ << " ";
	}//1 2 3
	cout << endl;

	auto re = find(v1.begin(),v1.end(),2);
	if (re != v1.end())
	{
		v1.insert(re, 30);
	}
	for (const auto& e : v1)
	{
		cout << e << " ";
	}//1 30 2 3
	cout << endl;

	v1.erase(v1.begin()+3);
	for (const auto& e : v1)
	{
		cout << e << " ";
	}//1 30 2 
	cout << endl;

	vector<int> v2({76,23,69,51});
	swap(v1,v2);
	for (const auto& e : v1)
	{
		cout << e << " ";
	}//76,23,69,51 
	cout << endl;

	for (size_t i = 0; i < v1.size(); i++)
	{
		cout << v1[i] << " ";
	}//76,23,69,51 
	cout << endl;

	v1.assign(3,3);
	for (const auto& e : v1)
	{
		cout << e << " ";
	}//3 3 3
	cout << endl;

}

int main()
{
	//vector_test01();
	//vector_test02();
	//vector_test03();
	vector_test04();

	return 0;
}